<%@ page language="java" import="com.ruohi.util.common.CnToFullSpell,com.ruohi.util.common.CommonForm"
         pageEncoding="UTF-8" %>
<%@ page import="com.ruohi.util.common.CommonString" %>
<%@ page import="com.ruohi.util.common.Env" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.TreeMap" %>
<%
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String tableName = "gift_product";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	String fileds = "id,uuid,no,name,category,brand,is_show";
	String whereStr = " and is_show=1 and index_rec_order_no is null";
	String orderByStr = " id desc";
	
	List<Map> brandList = (ArrayList)application.getAttribute("giftBrandList");
	//产品类别
	Map categoryMap = new TreeMap();
	List<Map> categoryList = (List)application.getAttribute("giftCategoryList");
	String n = "";
	String name = "";
	if(categoryList != null){
		for(Map m : categoryList){
			n = (String)m.get("no");
			name = (String)m.get("name");
			name = CommonForm.getHtmlSpaceByString((String)m.get("parent_no"))+name;
			categoryMap.put(n,name);
		}
	}
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>
  	<div class="searchForm">
  		<div class="searchCondition">
        	<div class="searchLeft">编号</div>
	  		<div class="searchRight">
	  			<input type="text" style="width: 120px;" name="no" class="jr_text" id="no" />
	  		</div>
	  		<div class="searchLeft">名称</div>
	  		<div class="searchRight">
	  			<input type="text" style="width: 120px;" name="name" class="jr_text" id="name" />
	  		</div>
            <div class="searchLeft">类别</div>
	  		<div class="searchRight">
	  			<select class="jr_select" id="category" name="category" >
                    <option value="">--请选择类别--</option>
                    <%=CommonForm.createSelect(categoryMap, "") %>
                </select>
	  		</div>
            <div class="searchLeft">品牌</div>
	  		<div class="searchRight">
	  			  <select class="jr_select" id="brand" name="brand">
                    <option value="">-请选择品牌-</option>
                    <%if(brandList != null){for(Map m : brandList){%>
                    <option value="<%=m.get("no")%>" ><%=CnToFullSpell.getFirstSpell(CommonString.getFormatPara(m.get("name"))).length()>=1?CnToFullSpell.getFirstSpell(CommonString.getFormatPara(m.get("name"))).substring(0,1):""%>-<%=CommonString.getFormatPara(m.get("name"))%></option>
                    <%}}%>
                  </select>
	  		</div>
	  		<div class="searchLeft">是否推荐</div>
	  		<div class="searchRight">
	  			<select class="jr_select" id="is_rec" name="is_rec" >
                    <option value="">--请选择--</option>
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
	  		</div>
  		</div>
  		<div class="searchBtn">
  			<input type="button" class="btn" onclick="doSearch();" value="查询" />
  			<input type="button" class="btn" onclick="doClearForm();" value="重置" />
  		</div>
  	</div>
	<div style="clear: left;"></div>
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript">
	var grid;
	var tableName = "<%=tableName %>";
	var channelUUID = '<%=channelUUID%>';
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	var myToolbar = {
        items: [{
            text: '显示到首页',
            click: function(){
                setIndexRec(1);
            },
            icon: 'add'
        },{
            text: '打开查询',
            click: function(){
                closeAndOpen();
            },
            icon: 'right'
        }]
    };
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013','fileName':'test'});
		grid = new Dev21sunGrid({
			toolbar : myToolbar
			});
		jQuery("#pageloading").hide();
	});
	//列数组
	columnsArr =  [ 
	{ display : '名称', name : 'name'  , id : 'no', align : 'left' , type : 'string' , width : 280 , render : function(row){
        return "<a target='_blank' href='http://www.52sdskj.com/product/" + row.no + ".htm'><img class='preview' src='/plugin/ui/ligerUI/ligerUI/skins/icons/preview.png' /></a>" + row.name;
			}
		} ,
	{ display : '编号', name : 'no'  , align : 'left' , type : 'string' , width : 150 }  ,
	{ display : '所在类别', name : 'category'  , align : 'left' , type : 'string' , width : 120 , render : function(row){
		return getGiftCategory(row.category,"giftCategoryMap");	
	}} ,
	{ display : '品牌', name : 'brand'  , align : 'left' , type : 'string' , width : 100 , render : function(row){
		return getGiftBrand(row.brand,"giftBrandMap");	
	}}
	];
	
	/*列表页条件查询*/
	function doSearch(){
		params = [];
		conditionStr = "";
		var no = jQuery("#no").val();
		if(''!=jQuery.trim(no)){
			conditionStr += " and no like '%"+no+"%' ";
		}
		var name = jQuery("#name").val();
		if(''!=jQuery.trim(name)){
			conditionStr += " and name like '%"+name+"%' ";
		}
		var category = jQuery("#category").val();
		if(''!=jQuery.trim(category)){
			conditionStr += " and category like '"+category+"%' ";
		}
		var brand = jQuery("#brand").val();
		if(''!=jQuery.trim(brand)){
			conditionStr += " and brand = '"+brand+"' ";
		}
		var is_rec = jQuery("#is_rec").val();
		if(''!=jQuery.trim(is_rec)){
			conditionStr += " and is_rec = '"+is_rec+"' ";
		}
		params.push({'name':'tableName','value':tableName});
		params.push({'name':'enumNo','value':'106013'});
		params.push({'name':'fields','value':fields});
		params.push({'name':'whereStr','value':conditionStr});
		params.push({'name':'orderBy','value':orderBy});
		grid.options.parms=params;
		grid.loadData();
	}
	
/**
 * 新品推荐方法
 * 
 * @param {}
 *            arg 推荐时要传的参数
 */
function setIndexRec(state) {
	var art;
	if (typeof(arg) == 'undefined' || arg == null) {
		arg = {};
	}
	var checkedRows = grid.getCheckedRows();
	if (checkedRows.length <= 0) {
		return;
	}
	// 遍历所有的选中行，如果是没有UUID，则移除
	jQuery.each(checkedRows, function(index, data) {
		if (typeof(this.uuid) == 'undefined') {
			jrDeleteRow(this.__index);
		}
	});
	jrConfirm("确定将选中项在首页的显示吗？", function(v) {
		if (v) {
			var checkedRows = grid.getCheckedRows();
			var idStr = "";
			for (var i = 0; i < checkedRows.length; i++) {
				idStr += "'" + checkedRows[i].uuid + "',";
			}
			if (idStr.indexOf(",") != -1) {
				idStr = idStr.substring(0, idStr.length - 1);
			}
			arg.del_id = idStr;
			if ('undefined' == typeof(arg.tableName)) {
				arg.tableName = tableName;
			}
			arg.state = state;
			executeSetIndexRec(arg);
		}
	});
}

/**
 * 执行删除的方法
 * 
 * @param {}
 *            data 要传向后台的数据
 */
function executeSetIndexRec(data) {
	var enumNo = '';
	for (var i = 0; i < params.length; i++) {
		if (params[i].name == 'enumNo') {
			enumNo = params[i].value;
		}
	}
	jQuery.ajax({
		url : '/backend/action/ajax_cud.jsp?enumNo=' + enumNo + '&flag=setIndexRec',
		data : data,
		type : 'post',
		async : false,
		cache : false,
		success : function(data) {
			grid.loadData();
		}
	});
}

function doSub(dialog){
	dialog.close();
}
</script>